<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="" %>
<%@include file="../include/jspheader.jsp" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<head>
<title>用户查询</title>

<script type="text/javascript" src="<s:url value="/js/formValidator3.5.js" includeParams="none"/>"></script>
<script type="text/javascript" src="<s:url value="/js/common.js" includeParams="none"/>"></script>
<script type="text/javascript" src="<s:url value="/js/lucenesearch.js" includeParams="none"/>"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("body").keydown(function(){
            if(event.keyCode == 13){
                initPageNum(); doSearch();
            }
        });
    });
function funReset(){
	$('#userName').val("");
    $('#email').val("");
	$('#beginTime').val("");
	$('#endTime').val("");
}

function checkSearchTime(createStartTime, createEndTime) {
	if (createStartTime.length > 0 && createStartTime.split("-").length == 3) {
		createStartTime = createStartTime.split("-");
		startTime = new Date(createStartTime[0], createStartTime[1]-1, createStartTime[2]);
	}//js中的Date类型月份是0-11月，所以要月份减1
	if (createEndTime.length > 0 && createEndTime.split("-").length == 3) {
		createEndTime = createEndTime.split("-");
		endTime = new Date(createEndTime[0], createEndTime[1]-1, createEndTime[2]);
	}
	if (startTime.getTime() > endTime.getTime()) {
		return "起始时间不能晚于结束时间！";
	}
}


function doSearch(){
	var userName = trimString($('#userName').val());
    var email = trimString($('#email').val());
	var createTimeBegin = $('#beginTime').val();
	var createTimeEnd = $('#endTime').val();
	if(createTimeBegin.length > 0 && createTimeEnd.length > 0){//如果开始和结束都选择了，检查开始时间是否小于结束时间
		var message = checkSearchTime(createTimeBegin, createTimeEnd);
		if (message != null && message.length > 0) {
			$('#diverror').html(message);
			return false;
		}
    }
	$('#searchform').submit();
}

function clickChangeRole(userId){
    $('#userId').val(userId);
	 popForm($('#change_role'));
}

</script>
</head>
<body>
<s:form id="searchform" name="searchform" method="post" namespace="/" action="listUser" theme="simple">
<div id="sa" class="sa2 p10 mb10">
	<table>
		<tr>
		    <th width="90">用户名：</th>
			<td width="300">
			    <input autocomplete="off" type="text" class="sa_w_tx" id="userName" name="query.userName" value="<s:property value="query.userName"/>" />
			</td>
			<th width="90">email：</th>
			<td width="300">
				<input type="text" class="sa_w_tx" id="email" name="query.email" value="<s:property value="query.email"/>" />
			</td>
		</tr>
		<tr>
		    <th width="90">注册时间：</th>
			<td width="300">
				<input type="text" class="date" name="query.beginTime" value='<s:date name="query.beginTime" format="yyyy-MM-dd" nice="false"/>' id="beginTime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true})" readonly="readonly"/> - <input type="text" name="query.endTime" value='<s:date name="query.endTime" format="yyyy-MM-dd" nice="false"/>' class="date" id="endTime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true})" readonly="readonly"/>
			</td>
			<th width="90"></th>
			<td width="300">
			</td>
		</tr>
		<tr>
			<th></th>
			<td><input type="button" value="查询" class="btn1" onclick="initPageNum(); doSearch();"/><input id="btnreset" type="button" value="重置" class="btn1" onclick="funReset();"/></td>
			<th></th>
			<td><font color="#FF0000"><div id="diverror"><s:fielderror id="fielderror"/></div></font></td>
		</tr>
	</table>
<s:actionmessage cssStyle="color:green;text-align:center;"/>
<s:actionerror cssStyle="color:red;text-align:center;"/>
</div>
<div id="sr" class="b1 mb10">
<table width="100%">
<tr>
<td>
	<ul id="sr_bq">
		<li class="on"><div>用户列表</div></li>
	</ul>
	<table width="100%" border="1" bordercolor="#d0d0d0" class="tb1" id="dgbg" bgcolor="#ffffff">
		<thead>
			<tr>
                <th width="1%" class="fs"></th>
				<th>用户ID</th>
				<th>用户名</th>
				<th>email</th>
				<th>公司名称</th>
                <th>注册时间</th>
                <th>所属角色</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<s:iterator value="userList">
				<tr>
                    <td class="fs"><input type="checkbox" name="checkEvent" value='<s:property value="id"/>'/></td>
				    <td><s:property value="id"/></td>
                    <td><s:property value="userName"/></td>
                    <td><s:property value="email"/></td>
                    <td><s:property value="company"/></td>
				    <td ><s:date name="createTime" format="yyyy-MM-dd HH:mm:ss" nice="false"/></td>
                    <td><s:property value="role"/></td>
				    <td>
				        <shiro:hasPermission name="user:changeRole">
                        <a href="#" onClick="clickChangeRole('<s:property value="id"/>')">编辑角色</a>
                        </shiro:hasPermission>
                        <shiro:hasPermission name="user:modify">
                        <a href="/xtx/viewModifyUser.action?user.id=<s:property value="id"/>">修改用户</a>
                        </shiro:hasPermission>
				    </td>
			  	</tr>
			</s:iterator>
		</tbody>
	</table>
<%@include file="../commons/pageNav.jsp" %>
</td>
</tr>
</table>
</div>
</s:form>
<div id="change_role" class="tips_ts">
	<div class="tips_ts1"><b id="b2">编辑权限</b><p class="simplemodal-close"><img src="/xtx/images/tips_close.gif" width="15" height="15" /></p></div>
	<div class="tips_ts2">
		<form method="post" action="changeRole.action" name="changeRoleForm" id="changeRoleForm">
            <select class="sa_w_se" id="eventType" name="query.roleId">
                <s:iterator value="roleList">
						<s:if test="name.equals(query.role)">
							<option value='<s:property value="code"/>' selected="selected"><s:property value="name"/></option>
						</s:if>
						<s:else>
							<option value='<s:property value="code"/>' ><s:property value="name"/></option>
						</s:else>
			    </s:iterator>
            </select>
            <input type="hidden" id="userId" name="query.id"/>
            <input type="submit" value="提交"/>
		</form>
	</div>
	<div class="tips_ts3"><img src="/xtx/images/tips_b.gif" width="420" height="10" /></div>
</div>
</body>
